package com.sensePlusVR.adapter;

import android.annotation.SuppressLint;
import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.sensePlusVR.bean.LocalVideoItem;
import com.sensePlusVR.main.R;
import com.sensePlusVR.utils.MyLog;

import java.util.List;

/**
 * 
 * @author: Loren
 * @create: 2016-8-10下午2:51:31
 * @desc: Local video Adapter
 *
 */
@SuppressLint("InflateParams")
@SuppressWarnings("unused")
public class LocalVideoAdapter extends
		RecyclerView.Adapter<LocalVideoAdapter.LocalVideoViewHolder> {

	private static final String TAG = LocalVideoAdapter.class.getSimpleName();
	private Context context;
	private List<LocalVideoItem> videoList;

	public LocalVideoAdapter(Context context, List<LocalVideoItem> videoList) {
		this.context = context;
		this.videoList = videoList;
	}

	@Override
	public LocalVideoViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
		View view = LayoutInflater.from(parent.getContext()).inflate(
				R.layout.fragment_video_local_item, parent,false);
		return new LocalVideoViewHolder(view);
	}

	@Override
	public void onBindViewHolder(LocalVideoViewHolder holder, final int position) {
		LocalVideoItem item = videoList.get(position);
		MyLog.d(TAG, "list size : " + videoList.size());
		holder.video_local_item_iv.setImageBitmap(item.getBitmap());
		holder.video_local_item_title.setText(item.getTitle());
		holder.video_local_item_time.setText(item.getLength());
		holder.video_local_item_size.setText(item.getSize());
	}

	@Override
	public int getItemCount() {
		return videoList.size();
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	public void removeItem(int position) {
		videoList.remove(position);
		notifyDataSetChanged();
	}

	public class LocalVideoViewHolder extends RecyclerView.ViewHolder {
		public ImageView video_local_item_iv;
		public TextView video_local_item_title;
		public TextView video_local_item_time;
		public TextView video_local_item_size;
		public TextView delete;
		public LinearLayout layout;

		public LocalVideoViewHolder(View itemView) {
			super(itemView);
			video_local_item_iv = (ImageView) itemView.findViewById(R.id.video_local_item_iv);
			video_local_item_title = (TextView) itemView
					.findViewById(R.id.video_local_item_title);
			video_local_item_time = (TextView) itemView
					.findViewById(R.id.video_local_item_time);
			video_local_item_size = (TextView) itemView
					.findViewById(R.id.video_local_item_size);
			delete = (TextView) itemView.findViewById(R.id.item_delete);
			layout = (LinearLayout) itemView.findViewById(R.id.item_layout);
		}
	}
}
